<?php

declare(strict_types=1);

namespace App\Amqp\Consumers;

use App\FundConf;
use App\Service\PriceLogService;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use Hyperf\Amqp\Result;
use PhpAmqpLib\Message\AMQPMessage;
use App\Service\FundBillService;
use Hyperf\Di\Annotation\Inject;

#[Consumer(exchange: "price", routingKey: "price", queue: "price", nums: 1, enable: true)]
class PriceConsumer extends ConsumerMessage
{
    //#[Inject]
    //private FundBillService $fundBillService;
    #[Inject]
    private PriceLogService $service;

    public function consumeMessage($queueData, AMQPMessage $message): Result
    {
        $opt = $queueData['opt'] ?? [];
        $data = $queueData['data'] ?? [];
        $fund_balance = $data['fund_balance'] ?? 0;
        $rs = null;
        if ($fund_balance > 0) {
            $rs = $this->service->changeByFund($fund_balance, 0);
        }
        $arr = compact('data', 'opt', 'rs');
        return Result::ACK;
    }

    public function isEnable(): bool
    {
        return parent::isEnable();
    }
}
